local xiaojun = fk.CreateSkill {

  name = "joy__xiaojun",

  tags = {  },

}



xiaojun:addEffect(fk.TargetSpecified, {
  name = "joy__xiaojun",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(xiaojun.name) and data.to ~= player.id then
      local to = player.room:getPlayerById(data.to)
      return not to.dead and to:getHandcardNum() >= 1 and U.isOnlyTarget(to, data, event)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local n = to:getHandcardNum()
    local m = n//2
    if n%2 > 0 then
      m = m + 1
    end
    event:setCostData(self, m)
    return player.room:askForSkillInvoke(player, xiaojun.name, nil,
      "#xiaojun-invoke::"..data.to..":"..tostring(m)..":"..data.card:getSuitString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local n = event:getCostData(self)
    local cards = room:askForCardsChosen(player, to, n, n, "h", xiaojun.name)
    room:throwCard(cards, xiaojun.name, to, player)
    if not player:isKongcheng() and data.card ~= Card.NoSuit and table.find(cards, function(id)
        return Fk:getCardById(id).suit == data.card.suit end) then
      room:askForDiscard(player, 1, 1, false, xiaojun.name, false)
    end
  end,
})

return xiaojun